package com.qf.util;

import lombok.Getter;

/**
 * @Author cuicui
 * @Description
 * @Date 2025-8-15
 */
public class R {
    @Getter
    private int code;
    private String msg;
    private Object data;

    public R() {
    }

    public R(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static R success() {
        R r = new R();
        r.setCode(2000);
        r.setMsg("成功");
        return r;
    }
    public static R success(Object data){
        R r = new R();
        r.setCode(2000);
        r.setMsg("成功");
        r.setData(data);
        return r;
    }
    public static R success(int num){
        R r = new R();
        r.setCode(2000);
        r.setMsg("成功");
        r.setData(num);
        return r;
    }
    public static R fail(){
        R r = new R();
        r.setCode(4000);
        r.setMsg("失败");
        return r;
    }
    public static R fail(int code,String msg){
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public void setCode(int code) {
        this.code = code;
    }

    /**
     * 获取
     * @return msg
     */
    public String getMsg() {
        return msg;
    }

    /**
     * 设置
     * @param msg
     */
    public void setMsg(String msg) {
        this.msg = msg;
    }

    /**
     * 获取
     * @return data
     */
    public Object getData() {
        return data;
    }

    /**
     * 设置
     * @param data
     */
    public void setData(Object data) {
        this.data = data;
    }

    public String toString() {
        return "R{code = " + code + ", msg = " + msg + ", data = " + data + "}";
    }
}
